package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 分页查询
     *
     * @return
     */
    Page<Employee> pageQuery(@Param("name") String name);

    /**
     * 新增员工
     *
     * @param employee
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into employee(name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user) " +
            "VALUES (#{emp.name}, #{emp.username}, #{emp.password}, #{emp.phone}, #{emp.sex}, #{emp.idNumber}, " +
            "#{emp.createTime}, #{emp.updateTime}, #{emp.createUser}, #{emp.updateUser})")
    void insertEmp(@Param("emp") Employee employee);

    /**
     * 启用或禁用员工账号
     *
     * @param employee
     */
    @AutoFill(OperationType.UPDATE)
    void updateEmp(Employee employee);

    /**
     * 根据id查询员工信息
     *
     * @param id
     * @return
     */
    @Select("select * from employee where id = #{id}")
    Employee getEmpById(Long id);
}
